package main.java.easy;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-22-22:46
 * @Description:
 */
public class StrStr {
    public static int strStr(String haystack,String needle){
        int left_index = 0;
        int right_index = 0;
        int n_index = 0;
        int n_len = needle.length();
        int h_len = haystack.length();
        if (n_len==0 || n_len > h_len ) return -1;
        while (left_index<= h_len - n_len){
            if (haystack.charAt(left_index)==needle.charAt(n_index)){
                right_index = left_index;
                while (haystack.charAt(right_index) == needle.charAt(n_index)){
                    if (n_index==n_len-1) return left_index;
                    right_index++;
                    n_index++;
                }
                n_index=0;
            }
            left_index++;
        }
        return -1;
    }

    public static void main(String[] args) {
        String s1 = "mississippi";
        String s2 = "issip";
        System.out.println(strStr(s1,s2));
    }
}
